home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / kgdb.sun3 / pinsn.c < prev    next >
C/C++ Source or Header  |  1989-08-10  |  19KB  |  838 lines

  1. /* Print m68k instructions for GDB, the GNU debugger.
  2.    Copyright (C) 1986, 1987, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. GDB is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GDB is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GDB; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include <stdio.h>
  21.  
  22. #include "defs.h"
  23. #include "param.h"
  24. #include "symtab.h"
  25. #include "opcode.h"
  26.  
  27. /* 68k instructions are never longer than this many bytes.  */
  28. #define MAXLEN 22
  29.  
  30. /* Number of elements in the opcode table.  */
  31. #define NOPCODES (sizeof m68k_opcodes / sizeof m68k_opcodes[0])
  32.  
  33. extern char *reg_names[];
  34. char *fpcr_names[] = { "", "fpiar", "fpsr", "fpiar/fpsr", "fpcr",
  35.              "fpiar/fpcr", "fpsr/fpcr", "fpiar-fpcr"};
  36.  
  37. static unsigned char *print_insn_arg ();
  38. static unsigned char *print_indexed ();
  39. static void print_base ();
  40. static int fetch_arg ();
  41.  
  42. #define NEXTBYTE(p)  (p += 2, ((char *)p)[-1])
  43.  
  44. #define NEXTWORD(p)  \
  45.   (p += 2, ((((char *)p)[-2]) << 8) + p[-1])
  46.  
  47. #define NEXTLONG(p)  \
  48.   (p += 4, (((((p[-4] << 8) + p[-3]) << 8) + p[-2]) << 8) + p[-1])
  49.  
  50. #define NEXTSINGLE(p) \
  51.   (p += 4, *((float *)(p - 4)))
  52.  
  53. #define NEXTDOUBLE(p) \
  54.   (p += 8, *((double *)(p - 8)))
  55.  
  56. #define NEXTEXTEND(p) \
  57.   (p += 12, 0.0)    /* Need a function to convert from extended to double
  58.                precision... */
  59.  
  60. #define NEXTPACKED(p) \
  61.   (p += 12, 0.0)    /* Need a function to convert from packed to double
  62.                precision.   Actually, it's easier to print a
  63.                packed number than a double anyway, so maybe
  64.                there should be a special case to handle this... */
  65.  
  66. /* Print the m68k instruction at address MEMADDR in debugged memory,
  67.    on STREAM.  Returns length of the instruction, in bytes.  */
  68.  
  69. int
  70. print_insn (memaddr, stream)
  71.      CORE_ADDR memaddr;
  72.      FILE *stream;
  73. {
  74.   unsigned char buffer[MAXLEN];
  75.   register int i;
  76.   register unsigned char *p;
  77.   register char *d;
  78.   register int bestmask;
  79.   int best;
  80.  
  81.   read_memory (memaddr, buffer, MAXLEN);
  82.  
  83.   bestmask = 0;
  84.   best = -1;
  85.   for (i = 0; i < NOPCODES; i++)
  86.     {
  87.       register unsigned int opcode = m68k_opcodes[i].opcode;
  88.       register unsigned int match = m68k_opcodes[i].match;
  89.       if (((0xff & buffer[0] & (match >> 24)) == (0xff & (opcode >> 24)))
  90.       && ((0xff & buffer[1] & (match >> 16)) == (0xff & (opcode >> 16)))
  91.       && ((0xff & buffer[2] & (match >> 8)) == (0xff & (opcode >> 8)))
  92.       && ((0xff & buffer[3] & match) == (0xff & opcode)))
  93.     {
  94.       /* Don't use for printout the variants of divul and divsl
  95.          that have the same register number in two places.
  96.          The more general variants will match instead.  */
  97.       for (d = m68k_opcodes[i].args; *d; d += 2)
  98.         if (d[1] == 'D')
  99.           break;
  100.  
  101.       /* Don't use for printout the variants of most floating
  102.          point coprocessor instructions which use the same
  103.          register number in two places, as above. */
  104.       if (*d == 0)
  105.         for (d = m68k_opcodes[i].args; *d; d += 2)
  106.           if (d[1] == 't')
  107.         break;
  108.  
  109.       if (*d == 0 && match > bestmask)
  110.         {
  111.           best = i;
  112.           bestmask = match;
  113.         }
  114.     }
  115.     }
  116.  
  117.   /* Handle undefined instructions.  */
  118.   if (best < 0)
  119.     {
  120.       fprintf (stream, "0%o", (buffer[0] << 8) + buffer[1]);
  121.       return 2;
  122.     }
  123.  
  124.   fprintf (stream, "%s", m68k_opcodes[best].name);
  125.  
  126.   /* Point at first word of argument data,
  127.      and at descriptor for first argument.  */
  128.   p = buffer + 2;
  129.   
  130.   /* Why do this this way? -MelloN */
  131.   for (d = m68k_opcodes[best].args; *d; d += 2)
  132.     {
  133.       if (d[0] == '#')
  134.     {
  135.       if (d[1] == 'l' && p - buffer < 6)
  136.         p = buffer + 6;
  137.       else if (p - buffer < 4 && d[1] != 'C' && d[1] != '8' )
  138.         p = buffer + 4;
  139.     }
  140.       if (d[1] >= '1' && d[1] <= '3' && p - buffer < 4)
  141.     p = buffer + 4;
  142.       if (d[1] >= '4' && d[1] <= '6' && p - buffer < 6)
  143.     p = buffer + 6;
  144.       if ((d[0] == 'L' || d[0] == 'l') && d[1] == 'w' && p - buffer < 4)
  145.     p = buffer + 4;
  146.     }
  147.  
  148.   d = m68k_opcodes[best].args;
  149.  
  150.   if (*d)
  151.     fputc (' ', stream);
  152.  
  153.   while (*d)
  154.     {
  155.       p = print_insn_arg (d, buffer, p, memaddr + p - buffer, stream);
  156.       d += 2;
  157.       if (*d && *(d - 2) != 'I' && *d != 'k')
  158.     fprintf (stream, ",");
  159.     }
  160.   return p - buffer;
  161. }
  162.  
  163. static unsigned char *
  164. print_insn_arg (d, buffer, p, addr, stream)
  165.      char *d;
  166.      unsigned char *buffer;
  167.      register unsigned char *p;
  168.      CORE_ADDR addr;        /* PC for this arg to be relative to */
  169.      FILE *stream;
  170. {
  171.   register int val;
  172.   register int place = d[1];
  173.   int regno;
  174.   register char *regname;
  175.   register unsigned char *p1;
  176.   register double flval;
  177.   int flt_p;
  178.  
  179.   switch (*d)
  180.     {
  181.     case 'C':
  182.       fprintf (stream, "ccr");
  183.       break;
  184.  
  185.     case 'S':
  186.       fprintf (stream, "sr");
  187.       break;
  188.  
  189.     case 'U':
  190.       fprintf (stream, "usp");
  191.       break;
  192.  
  193.     case 'J':
  194.       {
  195.     static struct { char *name; int value; } names[]
  196.       = {{"sfc", 0x000}, {"dfc", 0x001}, {"cacr", 0x002},
  197.          {"usp", 0x800}, {"vbr", 0x801}, {"caar", 0x802},
  198.          {"msp", 0x803}, {"isp", 0x804}};
  199.  
  200.     val = fetch_arg (buffer, place, 12);
  201.     for (regno = sizeof names / sizeof names[0] - 1; regno >= 0; regno--)
  202.       if (names[regno].value == val)
  203.         {
  204.           fprintf (stream, names[regno].name);
  205.           break;
  206.         }
  207.     if (regno < 0)
  208.       fprintf (stream, "%d", val);
  209.       }
  210.       break;
  211.  
  212.     case 'Q':
  213.       val = fetch_arg (buffer, place, 3);
  214.       if (val == 0) val = 8;
  215.       fprintf (stream, "#%d", val);
  216.       break;
  217.  
  218.     case 'M':
  219.       val = fetch_arg (buffer, place, 8);
  220.       if (val & 0x80)
  221.     val = val - 0x100;
  222.       fprintf (stream, "#%d", val);
  223.       break;
  224.  
  225.     case 'T':
  226.       val = fetch_arg (buffer, place, 4);
  227.       fprintf (stream, "#%d", val);
  228.       break;
  229.  
  230.     case 'D':
  231.       fprintf (stream, "%s", reg_names[fetch_arg (buffer, place, 3)]);
  232.       break;
  233.  
  234.     case 'A':
  235.       fprintf (stream, "%s", reg_names[fetch_arg (buffer, place, 3) + 010]);
  236.       break;
  237.  
  238.     case 'R':
  239.       fprintf (stream, "%s", reg_names[fetch_arg (buffer, place, 4)]);
  240.       break;
  241.  
  242.     case 'F':
  243.       fprintf (stream, "fp%d", fetch_arg (buffer, place, 3));
  244.       break;
  245.  
  246.     case 'O':
  247.       val = fetch_arg (buffer, place, 6);
  248.       if (val & 0x20)
  249.     fprintf (stream, "%s", reg_names [val & 7]);
  250.       else
  251.     fprintf (stream, "%d", val);
  252.       break;
  253.  
  254.     case '+':
  255.       fprintf (stream, "(%s)+", reg_names[fetch_arg (buffer, place, 3) + 8]);
  256.       break;
  257.  
  258.     case '-':
  259.       fprintf (stream, "-(%s)", reg_names[fetch_arg (buffer, place, 3) + 8]);
  260.       break;
  261.  
  262.     case 'k':
  263.       if (place == 'k')
  264.     fprintf (stream, "{%s}", reg_names[fetch_arg (buffer, place, 3)]);
  265.       else if (place == 'C')
  266.     {
  267.       val = fetch_arg (buffer, place, 7);
  268.       if ( val > 63 )        /* This is a signed constant. */
  269.         val -= 128;
  270.       fprintf (stream, "{#%d}", val);
  271.     }
  272.       else
  273.     error ("Invalid arg format in opcode table: \"%c%c\".",
  274.            *d, place);
  275.       break;
  276.  
  277.     case '#':
  278.     case '^':
  279.       p1 = buffer + (*d == '#' ? 2 : 4);
  280.       if (place == 's')
  281.     val = fetch_arg (buffer, place, 4);
  282.       else if (place == 'C')
  283.     val = fetch_arg (buffer, place, 7);
  284.       else if (place == '8')
  285.     val = fetch_arg (buffer, place, 3);
  286.       else if (place == '3')
  287.     val = fetch_arg (buffer, place, 8);
  288.       else if (place == 'b')
  289.     val = NEXTBYTE (p1);
  290.       else if (place == 'w')
  291.     val = NEXTWORD (p1);
  292.       else if (place == 'l')
  293.     val = NEXTLONG (p1);
  294.       else
  295.     error ("Invalid arg format in opcode table: \"%c%c\".",
  296.            *d, place);
  297.       fprintf (stream, "#%d", val);
  298.       break;
  299.  
  300.     case 'B':
  301.       if (place == 'b')
  302.     val = NEXTBYTE (p);
  303.       else if (place == 'w')
  304.     val = NEXTWORD (p);
  305.       else if (place == 'l')
  306.     val = NEXTLONG (p);
  307.       else if (place == 'g')
  308.     {
  309.       val = ((char *)buffer)[1];
  310.       if (val == 0)
  311.         val = NEXTWORD (p);
  312.       else if (val == -1)
  313.         val = NEXTLONG (p);
  314.     }
  315.       else if (place == 'c')
  316.     {
  317.       if (buffer[1] & 0x40)        /* If bit six is one, long offset */
  318.         val = NEXTLONG (p);
  319.       else
  320.         val = NEXTWORD (p);
  321.     }
  322.       else
  323.     error ("Invalid arg format in opcode table: \"%c%c\".",
  324.            *d, place);
  325.  
  326.       print_address (addr + val, stream);
  327.       break;
  328.  
  329.     case 'd':
  330.       val = NEXTWORD (p);
  331.       fprintf (stream, "%d(%s)", val, reg_names[fetch_arg (buffer, place, 3)]);
  332.       break;
  333.  
  334.     case 's':
  335.       fprintf (stream, "%s", fpcr_names[fetch_arg (buffer, place, 3)]);
  336.       break;
  337.  
  338.     case 'I':
  339.       val = fetch_arg (buffer, 'd', 3);          /* Get coprocessor ID... */
  340.       if (val != 1)                /* Unusual coprocessor ID? */
  341.     fprintf (stream, "(cpid=%d) ", val);
  342.       if (place == 'i')
  343.     p += 2;                 /* Skip coprocessor extended operands */
  344.       break;
  345.  
  346.     case '*':
  347.     case '~':
  348.     case '%':
  349.     case ';':
  350.     case '@':
  351.     case '!':
  352.     case '$':
  353.     case '?':
  354.     case '/':
  355.     case '&':
  356.  
  357.       if (place == 'd')
  358.     {
  359.       val = fetch_arg (buffer, 'x', 6);
  360.       val = ((val & 7) << 3) + ((val >> 3) & 7);
  361.     }
  362.       else
  363.     val = fetch_arg (buffer, 's', 6);
  364.  
  365.       /* Get register number assuming address register.  */
  366.       regno = (val & 7) + 8;
  367.       regname = reg_names[regno];
  368.       switch (val >> 3)
  369.     {
  370.     case 0:
  371.       fprintf (stream, "%s", reg_names[val]);
  372.       break;
  373.  
  374.     case 1:
  375.       fprintf (stream, "%s", regname);
  376.       break;
  377.  
  378.     case 2:
  379.       fprintf (stream, "(%s)", regname);
  380.       break;
  381.  
  382.     case 3:
  383.       fprintf (stream, "(%s)+", regname);
  384.       break;
  385.  
  386.     case 4:
  387.       fprintf (stream, "-(%s)", regname);
  388.       break;
  389.  
  390.     case 5:
  391.       val = NEXTWORD (p);
  392.       fprintf (stream, "%d(%s)", val, regname);
  393.       break;
  394.  
  395.     case 6:
  396.       p = print_indexed (regno, p, addr, stream);
  397.       break;
  398.  
  399.     case 7:
  400.       switch (val & 7)
  401.         {
  402.         case 0:
  403.           val = NEXTWORD (p);
  404.           fprintf (stream, "@#");
  405.           print_address (val, stream);
  406.           break;
  407.  
  408.         case 1:
  409.           val = NEXTLONG (p);
  410.           fprintf (stream, "@#");
  411.           print_address (val, stream);
  412.           break;
  413.  
  414.         case 2:
  415.           val = NEXTWORD (p);
  416.           print_address (addr + val, stream);
  417.           break;
  418.  
  419.         case 3:
  420.           p = print_indexed (-1, p, addr, stream);
  421.           break;
  422.  
  423.         case 4:
  424.           flt_p = 1;    /* Assume it's a float... */
  425.           switch( place )
  426.           {
  427.         case 'b':
  428.           val = NEXTBYTE (p);
  429.           flt_p = 0;
  430.           break;
  431.  
  432.         case 'w':
  433.           val = NEXTWORD (p);
  434.           flt_p = 0;
  435.           break;
  436.  
  437.         case 'l':
  438.           val = NEXTLONG (p);
  439.           flt_p = 0;
  440.           break;
  441.  
  442.         case 'f':
  443.           flval = NEXTSINGLE(p);
  444.           break;
  445.  
  446.         case 'F':
  447.           flval = NEXTDOUBLE(p);
  448.           break;
  449.  
  450.         case 'x':
  451.           flval = NEXTEXTEND(p);
  452.           break;
  453.  
  454.         case 'p':
  455.           flval = NEXTPACKED(p);
  456.           break;
  457.  
  458.         default:
  459.           error ("Invalid arg format in opcode table: \"%c%c\".",
  460.                *d, place);
  461.           }
  462.           if ( flt_p )    /* Print a float? */
  463.         fprintf (stream, "#%g", flval);
  464.           else
  465.         fprintf (stream, "#%d", val);
  466.           break;
  467.  
  468.         default:
  469.           fprintf (stream, "<invalid address mode 0%o>", val);
  470.         }
  471.     }
  472.       break;
  473.  
  474.     case 'L':
  475.     case 'l':
  476.     if (place == 'w')
  477.       {
  478.         char doneany;
  479.         p1 = buffer + 2;
  480.         val = NEXTWORD (p1);
  481.         /* Move the pointer ahead if this point is farther ahead
  482.            than the last.  */
  483.         p = p1 > p ? p1 : p;
  484.         if (val == 0)
  485.           {
  486.         fputs ("#0", stream);
  487.         break;
  488.           }
  489.         if (*d == 'l')
  490.           {
  491.         register int newval = 0;
  492.         for (regno = 0; regno < 16; ++regno)
  493.           if (val & (0x8000 >> regno))
  494.             newval |= 1 << regno;
  495.         val = newval;
  496.           }
  497.         val &= 0xffff;
  498.         doneany = 0;
  499.         for (regno = 0; regno < 16; ++regno)
  500.           if (val & (1 << regno))
  501.         {
  502.           int first_regno;
  503.           if (doneany)
  504.             putc ('/', stream);
  505.           doneany = 1;
  506.           fprintf (stream, "%s", reg_names[regno]);
  507.           first_regno = regno;
  508.           while (val & (1 << (regno + 1)))
  509.             ++regno;
  510.           if (regno > first_regno)
  511.             fprintf (stream, "-%s", reg_names[regno]);
  512.         }
  513.       }
  514.     else if (place == '3')
  515.       {
  516.         /* `fmovem' insn.  */
  517.         char doneany;
  518.         val = fetch_arg (buffer, place, 8);
  519.         if (val == 0)
  520.           {
  521.         fputs ("#0", stream);
  522.         break;
  523.           }
  524.         if (*d == 'l')
  525.           {
  526.         register int newval = 0;
  527.         for (regno = 0; regno < 8; ++regno)
  528.           if (val & (0x80 >> regno))
  529.             newval |= 1 << regno;
  530.         val = newval;
  531.           }
  532.         val &= 0xff;
  533.         doneany = 0;
  534.         for (regno = 0; regno < 8; ++regno)
  535.           if (val & (1 << regno))
  536.         {
  537.           int first_regno;
  538.           if (doneany)
  539.             putc ('/', stream);
  540.           doneany = 1;
  541.           fprintf (stream, "fp%d", regno);
  542.           first_regno = regno;
  543.           while (val & (1 << (regno + 1)))
  544.             ++regno;
  545.           if (regno > first_regno)
  546.             fprintf (stream, "-fp%d", regno);
  547.         }
  548.       }
  549.     else
  550.       abort ();
  551.       break;
  552.  
  553.     default:
  554.       error ("Invalid arg format in opcode table: \"%c\".", *d);
  555.     }
  556.  
  557.   return (unsigned char *) p;
  558. }
  559.  
  560. /* Fetch BITS bits from a position in the instruction specified by CODE.
  561.    CODE is a "place to put an argument", or 'x' for a destination
  562.    that is a general address (mode and register).
  563.    BUFFER contains the instruction.  */
  564.  
  565. static int
  566. fetch_arg (buffer, code, bits)
  567.      unsigned char *buffer;
  568.      char code;
  569.      int bits;
  570. {
  571.   register int val;
  572.   switch (code)
  573.     {
  574.     case 's':
  575.       val = buffer[1];
  576.       break;
  577.  
  578.     case 'd':            /* Destination, for register or quick.  */
  579.       val = (buffer[0] << 8) + buffer[1];
  580.       val >>= 9;
  581.       break;
  582.  
  583.     case 'x':            /* Destination, for general arg */
  584.       val = (buffer[0] << 8) + buffer[1];
  585.       val >>= 6;
  586.       break;
  587.  
  588.     case 'k':
  589.       val = (buffer[3] >> 4);
  590.       break;
  591.  
  592.     case 'C':
  593.       val = buffer[3];
  594.       break;
  595.  
  596.     case '1':
  597.       val = (buffer[2] << 8) + buffer[3];
  598.       val >>= 12;
  599.       break;
  600.  
  601.     case '2':
  602.       val = (buffer[2] << 8) + buffer[3];
  603.       val >>= 6;
  604.       break;
  605.  
  606.     case '3':
  607.     case 'j':
  608.       val = (buffer[2] << 8) + buffer[3];
  609.       break;
  610.  
  611.     case '4':
  612.       val = (buffer[4] << 8) + buffer[5];
  613.       val >>= 12;
  614.       break;
  615.  
  616.     case '5':
  617.       val = (buffer[4] << 8) + buffer[5];
  618.       val >>= 6;
  619.       break;
  620.  
  621.     case '6':
  622.       val = (buffer[4] << 8) + buffer[5];
  623.       break;
  624.  
  625.     case '7':
  626.       val = (buffer[2] << 8) + buffer[3];
  627.       val >>= 7;
  628.       break;
  629.       
  630.     case '8':
  631.       val = (buffer[2] << 8) + buffer[3];
  632.       val >>= 10;
  633.       break;
  634.  
  635.     default:
  636.       abort ();
  637.     }
  638.  
  639.   switch (bits)
  640.     {
  641.     case 3:
  642.       return val & 7;
  643.     case 4:
  644.       return val & 017;
  645.     case 5:
  646.       return val & 037;
  647.     case 6:
  648.       return val & 077;
  649.     case 7:
  650.       return val & 0177;
  651.     case 8:
  652.       return val & 0377;
  653.     case 12:
  654.       return val & 07777;
  655.     default:
  656.       abort ();
  657.     }
  658. }
  659.  
  660. /* Print an indexed argument.  The base register is BASEREG (-1 for pc).
  661.    P points to extension word, in buffer.
  662.    ADDR is the nominal core address of that extension word.  */
  663.  
  664. static unsigned char *
  665. print_indexed (basereg, p, addr, stream)
  666.      int basereg;
  667.      unsigned char *p;
  668.      FILE *stream;
  669.      CORE_ADDR addr;
  670. {
  671.   register int word;
  672.   static char *scales[] = {"", "*2", "*4", "*8"};
  673.   register int base_disp;
  674.   register int outer_disp;
  675.   char buf[40];
  676.  
  677.   word = NEXTWORD (p);
  678.  
  679.   /* Generate the text for the index register.
  680.      Where this will be output is not yet determined.  */
  681.   sprintf (buf, "[%s.%c%s]",
  682.        reg_names[(word >> 12) & 0xf],
  683.        (word & 0x800) ? 'l' : 'w',
  684.        scales[(word >> 9) & 3]);
  685.  
  686.   /* Handle the 68000 style of indexing.  */
  687.  
  688.   if ((word & 0x100) == 0)
  689.     {
  690.       print_base (basereg,
  691.           ((word & 0x80) ? word | 0xff00 : word & 0xff)
  692.           + ((basereg == -1) ? addr : 0),
  693.           stream);
  694.       fprintf (stream, "%s", buf);
  695.       return p;
  696.     }
  697.  
  698.   /* Handle the generalized kind.  */
  699.   /* First, compute the displacement to add to the base register.  */
  700.  
  701.   if (word & 0200)
  702.     basereg = -2;
  703.   if (word & 0100)
  704.     buf[0] = 0;
  705.   base_disp = 0;
  706.   switch ((word >> 4) & 3)
  707.     {
  708.     case 2:
  709.       base_disp = NEXTWORD (p);
  710.       break;
  711.     case 3:
  712.       base_disp = NEXTLONG (p);
  713.     }
  714.   if (basereg == -1)
  715.     base_disp += addr;
  716.  
  717.   /* Handle single-level case (not indirect) */
  718.  
  719.   if ((word & 7) == 0)
  720.     {
  721.       print_base (basereg, base_disp, stream);
  722.       fprintf (stream, "%s", buf);
  723.       return p;
  724.     }
  725.  
  726.   /* Two level.  Compute displacement to add after indirection.  */
  727.  
  728.   outer_disp = 0;
  729.   switch (word & 3)
  730.     {
  731.     case 2:
  732.       outer_disp = NEXTWORD (p);
  733.       break;
  734.     case 3:
  735.       outer_disp = NEXTLONG (p);
  736.     }
  737.  
  738.   fprintf (stream, "%d(", outer_disp);
  739.   print_base (basereg, base_disp, stream);
  740.  
  741.   /* If postindexed, print the closeparen before the index.  */
  742.   if (word & 4)
  743.     fprintf (stream, ")%s", buf);
  744.   /* If preindexed, print the closeparen after the index.  */
  745.   else
  746.     fprintf (stream, "%s)", buf);
  747.  
  748.   return p;
  749. }
  750.  
  751. /* Print a base register REGNO and displacement DISP, on STREAM.
  752.    REGNO = -1 for pc, -2 for none (suppressed).  */
  753.  
  754. static void
  755. print_base (regno, disp, stream)
  756.      int regno;
  757.      int disp;
  758.      FILE *stream;
  759. {
  760.   if (regno == -2)
  761.     fprintf (stream, "%d", disp);
  762.   else if (regno == -1)
  763.     fprintf (stream, "0x%x", disp);
  764.   else
  765.     fprintf (stream, "%d(%s)", disp, reg_names[regno]);
  766. }
  767.  
  768. /* This is not part of insn printing, but it is machine-specific,
  769.    so this is a convenient place to put it.
  770.  
  771.    Convert a 68881 extended float to a double.
  772.    FROM is the address of the extended float.
  773.    Store the double in *TO.  */
  774.  
  775. convert_from_68881 (from, to)
  776.      char *from;
  777.      double *to;
  778. {
  779. #ifdef KGDB
  780.     return;
  781. #endif
  782. #ifdef HPUX_ASM
  783.   asm ("mov.l 8(%a6),%a0");
  784.   asm ("mov.l 12(%a6),%a1");
  785.   asm ("fmove.x (%a0),%fp0");
  786.   asm ("fmove.d %fp0,(%a1)");
  787. #else /* not HPUX_ASM */
  788. #if 0
  789.   asm ("movl a6@(8),a0");
  790.   asm ("movl a6@(12),a1");
  791.   asm ("fmovex a0@,fp0");
  792.   asm ("fmoved fp0,a1@");
  793. #else
  794.   /* Hand-assemble those insns since some assemblers lose
  795.      and some have different syntax.  */
  796.   asm (".word 020156");
  797.   asm (".word 8");
  798.   asm (".word 021156");
  799.   asm (".word 12");
  800.   asm (".long 0xf2104800");
  801.   asm (".long 0xf2117400");
  802. #endif
  803. #endif /* not HPUX_ASM */
  804. }
  805.  
  806. /* The converse: convert the double *FROM to an extended float
  807.    and store where TO points.  */
  808.  
  809. convert_to_68881 (from, to)
  810.      double *from;
  811.      char *to;
  812. {
  813. #ifdef KGDB
  814.     return;
  815. #endif
  816. #ifdef HPUX_ASM
  817.   asm ("mov.l 8(%a6),%a0");
  818.   asm ("mov.l 12(%a6),%a1");
  819.   asm ("fmove.d (%a0),%fp0");
  820.   asm ("fmove.x %fp0,(%a1)");
  821. #else /* not HPUX_ASM */
  822. #if 0
  823.   asm ("movl a6@(8),a0");
  824.   asm ("movl a6@(12),a1");
  825.   asm ("fmoved a0@,fp0");
  826.   asm ("fmovex fp0,a1@");
  827. #else
  828.   /* Hand-assemble those insns since some assemblers lose.  */
  829.   asm (".word 020156");
  830.   asm (".word 8");
  831.   asm (".word 021156");
  832.   asm (".word 12");
  833.   asm (".long 0xf2105400");
  834.   asm (".long 0xf2116800");
  835. #endif
  836. #endif /* not HPUX_ASM */
  837. }
  838.